import { Link, Routes, Route, useParams } from "react-router-dom";

const Home = () => {
  return <div>home页面</div>;
};

const About = () => {
  return <div>about页面</div>;
};

const Detail = () => {
  // console.log(props);
  // 所有的页面都不能直接通过props拿到路由信息
  const params = useParams();
  console.log(params);

  return <div>详情页面</div>;
};

const App = () => {
  return (
    <>
      <h3>router-v6-params</h3>
      <ul>
        <li>
          <Link to="/home">home</Link>
        </li>
        <li>
          <Link to="/about">about</Link>
        </li>
        <li>
          <Link to="/detail/123">detail</Link>
        </li>
      </ul>

      <hr />

      <Routes>
        <Route path="/home" element={<Home />}></Route>
        <Route path="/about" element={<About />}></Route>
        {/* 动态路由写法相同 */}
        {/* <Route path="/detail/:id" element={<Detail />}></Route> */}

        {/* 动态可选路由，不管有没有传参数，都要能够显示那个页面 */}
        <Route path="/detail" element={<Detail />}>
          <Route path=":id" element={<Detail />}></Route>
        </Route>
      </Routes>
    </>
  );
};

export default App;
